package com.cn.dao;

import java.util.List;
import java.util.Set;

import javax.management.Query;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.cn.domain.Book;
import com.cn.domain.Category;

@SuppressWarnings("unchecked")
public class CategoryDao extends HibernateDaoSupport {

	public List<Category> findAllCategory() {
		String hql = "from Category ";
		List<Category> listcategory = this.getHibernateTemplate().find(hql);
		if (listcategory != null && listcategory.size() > 0) {
			return listcategory;
		}
		return null;
	}



	public Category  getCategoryId(int categoryid) {
	    Category  category =  (Category) this.getHibernateTemplate().get(Category.class,categoryid);
		if(category!=null) 
			return category;
	    return null;
	}


   //该分页下的总记录数
	public int findCountCategoryBook(int categoryid) {
		
	Category category = (Category) this.getHibernateTemplate().get(Category.class, categoryid);
		return category.getBooksetSet().size();

	}


   //该分页下的记录数
	public List<Book> findPageCateogry(int categoryid, int begin, int limitpage) {
		/*Category category = (Category) this.getHibernateTemplate().get(Category.class, categoryid);
		Set<Book> setbook = category.getBooksetSet();
	    */
     Session session = 	this.getSession();
     //session.createQuery(hql);
   return null;
	}



/*	public void updateCategoryId(Category category) {
	Category category =	getCategoryId(categoryid);
   
		return  this.getHibernateTemplate().update(category);
	}
*/


	public void deleteCategory(int categoryid) {
		// TODO Auto-generated method stub
		Category category =	getCategoryId(categoryid);
		this.getHibernateTemplate().delete(category);
	}



	public void updateCategory(Category category) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().update(category);
	}



	public void addCategory(Category category) {
		
		this.getHibernateTemplate().save(category);
		
	}



	



	




	
}
